package com.lanou3g.ssm.web;

import com.lanou3g.ssm.bean.Book;
import com.lanou3g.ssm.bean.LayUITableData;
import com.lanou3g.ssm.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/rest/book")
public class RestBookController {

    @Autowired
    private BookService bookService;

    /**
     * LayUI表格需要的JSON格式：
     * {
     *   "code": 0,
     *   "msg": "",
     *   "count": 1000,
     *   "data": [{}, {}]
     * }
     * @param model
     * @param condition
     * @return
     */
    @RequestMapping("/list")
    public LayUITableData<Book> queryBooks(Model model,
                                           @RequestParam(value = "page", required = false, defaultValue = "1") Integer currentPage,
                                           @RequestParam(value = "limit", required = false, defaultValue = "20") Integer pageSize,
                                           @RequestParam(required = false) Book condition) {
        return bookService.queryBooksForLayUI(null, pageSize, currentPage);
    }

}
